# -*- coding: UTF-8 -*-
# __author__ = 'Sengo'

from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
from cal_service import transformation

lines = ""
vertexes = ""


def init(d):
    glClearColor(0.0, 0.0, 0.0, 1.0)
    gluOrtho2D(-d, d, -d, d)


def draw_func():
    global lines
    global vertexes
    # lines
    for line in lines:
        ves = []
        for l in line:
            ves.append(vertexes[l])   # ves is the 3 vertexes in a face
        glColor3f(0.0, 1.0, 0.0)
        glLineWidth(1.0)
        glBegin(GL_LINE_LOOP)

        for v in ves:
            glVertex2f(v[0], v[1])
        glEnd()
    glFlush()


def draw(C, P, V_prime, d, f, h, graph_size, divide_w):
    global lines
    global vertexes
    # init data

    vertexes, lines = transformation(C, P, V_prime, d, f, h, divide_w)
    glutInit()
    glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE)
    glutInitWindowSize(600, 600)
    glutCreateWindow("lab1")
    glutDisplayFunc(draw_func)
    init(graph_size)
    glutMainLoop()





